package public

import (
	"github.com/e421083458/golang_common/lib"
	"github.com/garyburd/redigo/redis"
)

//GetStore 从redis中读取
func GetStore(key string) (string, error) {
	trace := lib.NewTrace()
	tx, err := lib.RedisConnFactory("default")
	if err != nil {
		return "", err
	}
	defer tx.Close()
	v, err := redis.String(lib.RedisLogDo(trace, tx, "GET", key))
	if err != nil {
		return "", err
	}
	return v, nil
}

//SetStore 写入redis
func SetStore(key, value string, exp int) error {
	track := lib.NewTrace()
	tx, err := lib.RedisConnFactory("default")
	if err != nil {
		return err
	}
	defer tx.Close()
	lib.RedisLogDo(track, tx, "SET", key, value)
	lib.RedisLogDo(track, tx, "expire", key, exp)
	return nil
}
